package com.zz.itext7;



import com.itextpdf.forms.PdfAcroForm;
import com.itextpdf.forms.fields.PdfFormField;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;

import java.util.Map;

//获取现有模板并对现有的模板进行数据合成
public class demo1 {
    public static void main(String[] args) throws  Exception{
        PdfDocument pdf = new PdfDocument(new PdfReader("D:\\测试pdf\\demo1.pdf"),new PdfWriter("D:\\测试pdf\\day4_3.pdf"));
        Document doc = new Document(pdf);
        PdfAcroForm from = PdfAcroForm.getAcroForm(pdf,true);
        Map<String, PdfFormField> formFields = from.getFormFields();
        formFields.forEach((o,s)->formFields.get(o).setValue("振"));
        System.out.println(formFields.size());
        /*Map<String, PdfFormField> map = from.getFormFields();
        map.get("hkzl").setValue("测试数据");*/
        from.flattenFields();
        pdf.close();
    }

}
